home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PRINTER / PROHP.ARJ / DPRINV.PRG < prev    next >
Text File  |  1992-06-23  |  9KB  |  243 lines

  1. /*
  2.   ┌─────────────────────────────────────────────────────────────────────────┐
  3.   │                                                                         │
  4.   │   Program : Prinv.prg                                                   │
  5.   │   Usage   :                                                             │
  6.   │   Purpose : Demonstrate creating an invoices form with shadow boxes     │
  7.   │             store it to a string type var make it as a macro and        │
  8.   │             call it each time we need the form.                         │
  9.   │             also the option of saving the invoice to a file             │
  10.   │             and download it later.                                      │
  11.   │                                                                         │
  12.   │   Author  : Copyright (C) 1992, I.L.A.,Inc. All Rights reserved.        │
  13.   │                                                                         │
  14.   │   Comments: This source code may be distributed and used freely         │
  15.   │             provided that the copyright notice is not removed.          │
  16.   │                                                                         │
  17.   └─────────────────────────────────────────────────────────────────────────┘
  18. */
  19.  
  20. #include "prohp.ch"
  21.  
  22. proc main()
  23. Local HPCinv:=""
  24. set2print("dprinv.hpc")
  25. HP_init()
  26. HP_send(.T.)
  27. // process the invoice internaly
  28.  
  29. HPscale(50)
  30. PrInvoice(1,1,10,5)
  31.  HP_reset()
  32.  
  33.  HP_orient(LANDSCAPE)
  34. HPscale(100)
  35. PrInvoice(0.3,0.3,9.5,3.5)
  36.  HP_reset()
  37.  
  38.  HP_orient(PORTRAIT)
  39. HPscale(100)
  40. PrInvoice(1,1,6,5)
  41.  HP_reset()
  42.  
  43. // now we will test downloading this invoice
  44. // DLinvoice()
  45. // HP_reset()
  46.  
  47. set2screen()
  48. return
  49.  
  50. Function PrInvoice(nTop,nLeft,nWidth,nInvH)
  51. Local nInvoice:= 18000, nTotInv := 0
  52. Local nRscale:=HPscale()/100  // used to adjust scale where
  53.                               // HPscale() has no efect
  54. Local aCompany:={"I.L.A., Inc. ","520 W. Hwy 436 #1180",;
  55.                  "Altamonte Springs, FL 32714","Fax. (407) 774-6750"}
  56. // Local nTop:=0.3,nLeft:=0.3
  57. Local nLogoH:=2.2*nRscale
  58. //Local nWidth:=7    // try changing the width and all the rest
  59.                      // will be adjusted try it !
  60. // Local nInvH:=5.5
  61. Local nInvW:=nWidth
  62. Local o:='',nBoxSpace:=0.2
  63. Local nS2H:=1         // height of Sold to / ship to box
  64. Local nS2W:=(nWidth-nBoxSpace)/2   // width of S2/S2 box
  65. Local aSold2Box:={nTop+nLogoH,nLeft,nS2H,nS2W}  //
  66. Local aShip2Box:={nTop+nLogoH,nLeft+(nS2W*nRscale)+(nBoxSpace*nRscale),nS2H,nS2W}
  67. Local aInvBox:={nTop+nLogoH+(aSold2Box[3]*nRscale)+(nBoxSpace*nRscale),nLeft,nInvH,nInvW}
  68. local nWUnit:=nWidth/10*nRscale
  69. // set array of Invoice column width
  70. Local aColW:={nWUnit*1,nWUnit*6,nWUnit*1.2,nWUnit*1.8}
  71. Local aInvTab:={nLeft,nLeft+nWUnit,nLeft+nWUnit*7,nLeft+nWUnit*8.2}
  72. //Local aInvTab:={nLeft,aColW[1],aColW[1]+aColW[2],aColW[1]+aColW[2]+aColW[3]}
  73. Local line:=0,nttop:=0,cInvoice:="",os,HPCinv:=''
  74. Local ntdate,nQty,nUnitp,cDescr,aaddress,nLM
  75. os:=HP_send(.f.)
  76. HPshadow(.t.)          // make shadow boxes
  77. HPsetshadow(HPsetshadow()[1]*nRscale) // set shadow width
  78. if HPscale() < 80
  79.    HPCinv+=HP_pitch(16,ITALIC)
  80.    HPCinv+=HP_lpi(8)
  81. else
  82.    HPCinv+=HP_pitch(10,ITALIC)
  83.    HPCinv+=HP_lpi(5)
  84. endif
  85. ntTop:=nTop
  86. // print company header
  87. HPCinv+=HP_hline(ntTop,nLeft,nWidth,0.08,GFILLGRAY,40)
  88. ntTop+=1.5/HP_data(D_LPI)
  89. for line:=1 to len(aCompany)
  90.     HPCinv+=HP_atsay(ntTop,nLeft,aCompany[line])
  91.     ntTop+=1/HP_data(D_LPI)
  92. next
  93. HPCinv+=HP_hline(ntTop,nLeft,nWidth,0.08,GFILLGRAY,40)
  94.  
  95. ntTop+=1/HP_data(D_LPI)+0.08
  96. nTdate:=ntTop   // mark date line for later
  97. // HPCinv+=HP_lpi(7)
  98.  
  99. // make "sold to" box
  100. HPCinv+=HP_box(aSold2Box[1],aSold2Box[2],aSold2Box[3],aSold2Box[4])
  101. HPCinv+=HP_atsay(aSold2Box[1]-0.5/HP_data(D_LPI),aSold2Box[2],"Sold To:")
  102. // make "ship to" box
  103. HPCinv+=HP_box(aShip2Box[1],aShip2Box[2],aShip2Box[3],aShip2Box[4])
  104. HPCinv+=HP_atsay(aShip2Box[1]-0.5/HP_data(D_LPI),aShip2Box[2],"Ship To:")
  105. // make invoice detail box
  106. HPCinv+=HP_box(aInvBox[1],aInvBox[2],aInvBox[3],aInvBox[4])
  107. HPCinv+=HP_hline(aInvBox[1]+1.5/HP_data(D_LPI),aInvBox[2],aInvBox[4])
  108. HPCinv+=HP_hline(aInvBox[1],aInvBox[2],aInvBox[4],1.5/HP_data(D_LPI),GFILLGRAY,10)
  109. HPCinv+=HP_pitch(16)      // use small font for column header
  110. // print column header at center of each col.
  111. HPCinv+=HP_atsay(aInvBox[1]+1/HP_data(D_LPI),aInvBox[2]+;
  112.         (aColW[1]-HPstsize("QTY."))/2,"QTY.")
  113. HPCinv+=HP_vline(aInvBox[1],aInvBox[2]+aColW[1],aInvBox[3])
  114. HPCinv+=HP_atsay(aInvBox[1]+1/HP_data(D_LPI),aInvBox[2]+aColW[1]+;
  115.         (aColW[2]-HPstsize("Description"))/2,"Description")
  116. HPCinv+=HP_vline(aInvBox[1],aInvBox[2]+aColW[1]+aColW[2],aInvBox[3])
  117. HPCinv+=HP_atsay(aInvBox[1]+1/HP_data(D_LPI),aInvBox[2]+aColW[1]+aColw[2]+;
  118.         (aColW[3]-HPstsize("Unit"))/2,"Unit")
  119. HPCinv+=HP_vline(aInvBox[1],aInvBox[2]+aColW[1]+aColW[2]+aColW[3],aInvBox[3])
  120. HPCinv+=HP_atsay(aInvBox[1]+1/HP_data(D_LPI),aInvBox[2]+aColW[1]+aColw[2]+aColW[3]+;
  121.         (aColW[4]-HPstsize("Amount"))/2,"Amount")
  122. // Invocie format is done and we have all it in HPCinv
  123. HP_send(os)     // restore output flag
  124. if HPscale() < 80
  125.    HP_pitch(16)
  126. else
  127.     HP_pitch(10,ITALIC)
  128. endif
  129. nInvoice:=18000         // invoice # to start
  130. nQty:=1                  // quantity
  131. cDescr:="ProHP - Library for Laser Printer"      // description
  132. nUnitp:=99.00            // unit price
  133. nLM:=1/HP_data(D_CPI)   // Relative Left margin for column
  134.  
  135. /*
  136.    one option is to save this invoice format to a disk file for later use
  137.    one easy way is to save it using memowrit() and later download the
  138.    invoice using memoread(). do not forget to save the invoice coordinates
  139.    to print the invoice details after downloading.
  140. */
  141. memowrit("invoice.mac",HPCinv)    // save Invoice format to a file
  142.  
  143. // Open DBF file
  144. select 1
  145. use prohp alias pro
  146. go top
  147.  
  148. /*
  149.    Let's store the invoice format into Macro so we do not need to send it
  150.    to the printer each time we print an invoice. it is faster because the
  151.    macro is stored in the printer memory and to activate it you send only
  152.    a call macro command.
  153. */
  154.    
  155.  HP_stmacro(1)   // open macro id # 1
  156. qqout(HPCinv)     // send to printer
  157.  HP_endmacro(1,PERMMACRO)        // close macro 1 and save it from reset
  158. if HPscale() < 80
  159.     HP_pitch(16)
  160.     HP_lpi(8)
  161. else
  162.      HP_pitch(10,ITALIC)         // set font to Courier 10 cpi Italic
  163.      HP_lpi(5)                   // 5 lines per inch
  164. endif
  165. while !eof()
  166.      HP_callmacro(1)             // call macro # 1 (our invoice format)
  167.     // print date and invoice #
  168.      HP_atsay(nTdate,nLeft,"Date :"+dtoc(date()))
  169.     cInvoice:="Invoice  #  "+str(nInvoice,6)
  170.     // Right justify Invoice #
  171.      HP_atsay(nTdate,nLeft+(nWidth*nRscale)-HPstsize(cInvoice),cInvoice)
  172.     // read address into array
  173.     aAddress:={pro->name,pro->address,trim(pro->city)+', '+pro->state+' '+;
  174.               pro->zip}
  175.     // print Sold to and ship to address location using HP_aatsay()
  176.      HP_aatsay(aSold2Box[1]+1/HP_data(D_LPI),aSold2Box[2]+nLM,aAddress)
  177.      HP_aatsay(aShip2Box[1]+1/HP_data(D_LPI),aShip2Box[2]+nLM,aAddress)
  178.     // detail of invoice
  179.      HP_setpos(aInvBox[1]+2/HP_data(D_LPI),nLeft+nLM)
  180.     // while invoice here
  181.      HP_rcpos(1,,.t.)  // down one line
  182.     // print quantity
  183.      HP_atsay(,aInvTab[1]+nLm,padl(str(nQty,4),HPi2col(aColW[1])-1))
  184.     // print description
  185.      HP_atsay(,aInvTab[2]+nLm,cDescr)
  186.     // print unit price
  187.      HP_atsay(,aInvTab[3]+nLm,padl(str(nUnitp,6,2),HPi2col(aColW[3])-1))
  188.       // print amount
  189.      HP_atsay(,aInvTab[4]+nLm,padl(str(nQty*nUnitp,9,2),HPi2col(aColW[4])-1))
  190.     nTotInv+=nQty*nUnitp
  191.     // enddo here
  192.  
  193.     // print totals
  194.      HP_rcpos(2,,.t.) // 2 lines down
  195.  
  196.     // print Total Amount
  197.     // first draw gray bar over the current line
  198.      HP_atsay(,aInvTab[2],HPgraytext(padl("",;
  199.         HPi2col(aColW[2]+aColW[3]+aColW[4]))))
  200.     // print 'Total '
  201.      HP_atsay(,aInvTab[3]-HPstsize("Total "),"Total ")
  202.     // Print the total amount
  203.      HP_atsay(,aInvTab[4]+nLm,padl(str(nTotInv,9,2),;
  204.         HPi2col(aColW[4])-1))
  205.     // print message at the bottom of the invoice
  206.      HP_atsay(aInvBox[1]+(aInvBox[3]*nRscale)-1/HP_data(D_LPI),aInvTab[2]+nLm,;
  207.             HPbold("DO NOT FORGET TO SEND REGISTRATION CARD."))
  208.  
  209.     nInvoice++          // increment invoice number
  210.      HP_feed(FEEDOUT)    // feed the page out. (no change to the printer environment)
  211.     if nInvoice=18001
  212.        exit
  213.     endif
  214.     skip        // next record
  215. enddo
  216. return NIL
  217.  
  218.  
  219. proc DLinvoice()
  220. /*
  221.         This procedure demonstrate how it is simple and fast to
  222.         download previuosly built forms of any kind.
  223.         the two methods will work fine with most cases but we recomend
  224.         the use of HPdownload() which send the file in binary mode to
  225.         the printer and return .F. if error occur during downloading.
  226. */
  227.  
  228. Local HPCinv:=[], cfName:="invoice.mac"
  229.  
  230. if file(cfName)         // make sure we have the file
  231.    HP_pitch(10)
  232.    HP_atsay(5,2,"Using MEMOREAD()")
  233.    HPCinv := memoread(cfName)
  234.    qqout(HPCinv)          // or just qqout(memoread(cfName))
  235.  
  236.    HP_feed(FEEDOUT)
  237.    HPdownload(cfName,"LPT1")    // download invoice format
  238.    HP_atsay(5,2,"USING HPdownload()")
  239. endif
  240. return
  241.  
  242.  
  243.